<fieldset class="solid">
	<legend>创建tbProject</legend>
	<input type="hidden" name="tbProject.id" value="#(tbProject.id??)" />
	<input type="hidden" name="tbProject.createTime" value="#(tbProject.createTime??)" />
	<input type="hidden" name="tbProject.updateTime" value="#(tbProject.updateTime??)" />
	<div>
		<label>标题</label>
		<input type="text" name="tbProject.title" value="#(tbProject.title??)" />
	</div>
	<div>
		<label>项目类型</label>
		<select name="tbProject.type" id="projectTypeSelect">
			<option value="1">java</option>
			<option value="0">vue</option>
		</select>
	</div>
	<div>
		<label>是否上传工程</label>
		<select name="tbProject.uploadFile">
			#if(tbProject.uploadFile?? == 1)
			<option value="1" selected>是</option>
			<option value="0">否</option>
			#else
			<option value="1">是</option>
			<option value="0" selected>否</option>
			#end
		</select>
	</div>

	<div id="scmBuildProject">

		<div>
			<label>OS类型</label>
			<select name="tbProject.os" id="osSelectId">
				#if(tbProject.os?? == 'linux')
				<option value="linux" selected>linux</option>
				<option value="windows">windows</option>
				#else
				<option value="linux" selected>linux</option>
				<option value="windows" selected>windows</option>
				#end
			</select>
		</div>
		<div>
			<label>关联工程</label>
			<select name="tbProject.relatedId">
				<option value="0">无关联工程</option>
				#for(x : projectList)
				#if(tbProject.relatedId?? == x.id)
				<option value="#(x.id)" selected>#(x.title)</option>
				#else
				<option value="#(x.id)">#(x.title)</option>
				#end
				#end

			</select>
		</div>
		<div>
			<label>脚本模板</label>
		#if(tbProject.id?? == null)
			<select id="templateSelectId">
				#for(x : templateList)
				<option value="#(x.id)">#(x.name)</option>
				#end
			</select>
		#else
			编辑无法选择模板
		#end
		</div>
		<div>
			<label>项目负责人</label>
			<input type="text" name="tbProject.dutyPerson" value="#(tbProject.dutyPerson??)" />
		</div>
		<div>
			<label>代码仓库</label>
			<input type="text" name="tbProject.scmPath" value="#(tbProject.scmPath??)" />
		</div>
		<div>
			<label>代码仓库-账号信息</label>
			<select name="tbProject.accountId" id="tbProject.accountId" onchange="hideGitInfo(this)">
				<option value="0">本地不编译工程</option>
				#for(x : tbAccountList)
					#if(tbProject.accountId?? == x.id)
						<option value="#(x.id)" selected>#(x.userName)/**</option>
					#else
						<option value="#(x.id)">#(x.userName)/**</option>
					#end
				#end

			</select>
		</div>
		<div id="gitInfo">
			<div>
				<label>手机号</label>
				<input type="text" name="tbProject.phone" value="#(tbProject.phone??)" />
			</div>
			<div>
				<label>脚本名称</label>
				<input type="text" name="tbProject.scriptFilePath" value="#(tbProject.scriptFilePath??)" />
			</div>
			<div>
				<label>执行脚本</label>
				<textarea name="tbProject.script" id="script" cols="200" rows="50">#(tbProject.script??)</textarea>#(contentMsg)
			</div>
		</div>
	</div>
<!--	end scmBuild div-->
	<div>
		<label>ssh-账号信息</label>
		<select name="tbProject.sshAccountId">
			<option value="0">不上传ssh</option>
			#for(x : tbAccountList)
			#if(tbProject.sshAccountId?? == x.id)
			<option value="#(x.id)" selected>#(x.type)/**</option>
			#else
			<option value="#(x.id)">#(x.type)/**</option>
			#end
			#end

		</select>
	</div>
	<div>
		<pre>
		1 #!/bin/sh
		2 系统安装 yum -y install dos2unix
		</pre>
	</div>
	<div>
		<label>子工程-部署工程信息</label>
		<div id="jsonConfigDiv">
			#for(obj : subProjects)
			<div>
				<input type="text" class="demo demo-textarea" title="工程路径 v4-common-parent/v4-nuo-service-user"  value="#(obj.projectPath)">
				<input type="text" class="demo demo-textarea" title="工程名称 target/v4-nuo-service-user.jar" value="#(obj.projectName)">

				<select>
					#if(obj.zip)
						<option value="1" selected>压缩</option>
						<option value="0">不压缩</option>
					#else
						<option value="1">压缩</option>
						<option value="0" selected>不压缩</option>
					#end
				</select>
				<input type="text" class="demo demo-textarea" title="选择压缩的文件夹或者文件 用空格分开" value="#(obj.zipFolderOrFile)">

				<select>
					<option value="0">不上传ssh</option>
					#for(x : tbAccountList)
						#if(obj.sshId?? == x.id)
						<option value="#(x.id)" selected>#(x.type)/**</option>
						#else
						<option value="#(x.id)">#(x.type)/**</option>
						#end
					#end

				</select>
				<textarea cols="200" rows="10">#(obj.sshScript??)</textarea>
				<input type="text" class="demo demo-textarea" title="部署目录前缀" value="#(obj.sshTargetDir)">
				<div> <a onclick="delOneLunbo(this)">删除本条</a> </div>
				<hr/>
			</div>
			#end
		</div>
	</div>
	<div>
		<label>添加</label>
		<button type="button" class="btn btn-primary" onclick="addUrl()">子工程部署信息</button>
	</div>

	<div>
		<label>edas-账号信息</label>
		<select name="tbProject.eadsAccountId">
			<option value="0">不调用edas API</option>
			#for(x : tbAccountList)
				#if(tbProject.eadsAccountId?? == x.id)
				<option value="#(x.id)" selected>#(x.type)/**</option>
				#else
				<option value="#(x.id)">#(x.type)/**</option>
				#end
			#end

		</select>
	</div>
	<div>
		<label>edasAppId</label>
		<input type="text" name="tbProject.edasAppId" value="#(tbProject.edasAppId??)" />
	</div>
	<div>
		<label>版本号</label>
		<input type="text" name="tbProject.edasPackageVersion" value="#(tbProject.edasPackageVersion??)" />
	</div>
	<div>
		<label>&nbsp;</label>
		<input value="提交" type="submit">
<!--		<input value="test" type="button" onclick="appendJsonConfig()">-->
	</div>
</fieldset>
<script type="text/javascript">

	$(function(){
		//是否隐藏git构建信息
		hideGitInfo(document.getElementById("tbProject.accountId"));

		$("#projectTypeSelect").val("#(tbProject.type??)");
　　	$("#templateSelectId").change(function(){
			var select_val = $(this).children('option:selected').val();
			console.log(select_val);
			var os = $("#osSelectId").val();
			$.post("/project/getTemplate?id="+select_val+"&os="+os,function(result){
				console.log(result);
				if(result){
					$("#script").val(result.script);
				}else{
					alert('没有对应的模板');
				}
			});
		});
　　　　//adding your code here
　　});

	//是否隐藏-代码相关配置
	function hideGitInfo(selectObj){
		var aaa = $(selectObj).val();
		if(aaa == 0){
			$("#gitInfo").hide();
		}else{
			$("#gitInfo").show();
		}
	}

	//克隆一个url 追加
    function addUrl(){
    	var firstChild = $("#jsonConfigDiv").children(":first");
    	if(firstChild.length != 0){
			var cloneUrl = firstChild.clone();
        	$("#jsonConfigDiv").append(cloneUrl);
    	}else{
			//没有任何信息,需要自动拼装一个
			$("#jsonConfigDiv").append(dynimicHtml());
    	}

    }

    function dynimicHtml(){

    	var str =
				'<div>' +
				'<input type=\"text\" class=\"demo demo-textarea\" title=\"工程路径 v4-common-parent/v4-service-user\" value=\"v4-common-parent/v4-service-user/target\">' +
				'<input type=\"text\" class=\"demo demo-textarea\" title=\"工程名称 target/v4-service-user.jar\" value=\"v4-service-user\">' +
				'<select>' +
				'<option value=\"1\" selected=\"\">压缩</option>' +
				'<option value=\"0\">不压缩</option>' +
				'</select>' +
				'<input type=\"text\" class=\"demo demo-textarea\" title=\"选择压缩的文件夹或者文件 用空格分开\" value=\"lib v4-service-user.jar\">' +
				'<select>' +
				'<option value=\"0\">不上传ssh</option>' +
				'<option value=\"2\"  selected=\"\">2/**</option>' +
				'</select>' +
				'<textarea cols=\"200\" rows=\"10\">#!/bin/sh' +
				'source /mnt/data/#(subProjectName)/runApp.sh' +
				'</textarea>' +
				'<input type=\"text\" class=\"demo demo-textarea\" title=\"部署目录前缀\" value=\"/mnt/data\">' +
				'<div> <a onclick=\"delOneLunbo(this)\">删除本条</a> </div>' +
				'<hr>' +
				'</div>';

				return str;
    }

    //删除一个
    function delOneLunbo(obj){
        $(obj).parent().parent().remove();
    }

	//提交表单的时候，把 子工程信息 拼接成json格式
    function appendJsonConfig(){
        var subProjects = [];
        console.log("size-----   "+$("#jsonConfigDiv").children().length);
        $("#jsonConfigDiv").children().each(function(){
            //console.log(this.innerHTML);
            console.log(this);
            //console.log($(this).children().length);
            var url = {};
            $(this).children().each(function(index){
            	//console.log(this);
                if(this.value){
                    //console.log(index+" : "+this.value);
                    if(index == 0){
                        url.projectPath = this.value;
                    }else if(index == 1){
                        url.projectName = this.value;
                    }else if(index == 2){
                        url.zip = this.value==1?true:false;
                    }else if(index == 3){
                        url.zipFolderOrFile = this.value;
                    }else if(index == 4){
                        url.sshId = this.value;
                    }else if(index == 5){
                        url.sshScript = this.value;
                    }else if(index == 6){
                        url.sshTargetDir = this.value;
                    }
                }
            });
            subProjects.push(url);
        });
        var jsonValue = JSON.stringify(subProjects);
        console.log(jsonValue);
        $("#projectForm").append("<input type='hidden' name='tbProject.subProjectJson' value='" + jsonValue + "'/>");
        return true;
    }
</script>